package com.company.ems.util;

import java.sql.*;

public class DatabaseUtil {
    // 更新数据库名称为新的作业数据库
    private static final String URL = "jdbc:mysql://159.75.137.11:3306/ems_assignment?useSSL=false&serverTimezone=UTC&characterEncoding=utf8";
    private static final String USERNAME = "admin";
    private static final String PASSWORD = "soft2025";
    
    static {
        try {
            Class.forName("com.mysql.cj.jdbc.Driver");
        } catch (ClassNotFoundException e) {
            e.printStackTrace();
        }
    }
    
    public static Connection getConnection() throws SQLException {
        return DriverManager.getConnection(URL, USERNAME, PASSWORD);
    }
    
    public static void closeConnection(Connection conn, Statement stmt, ResultSet rs) {
        try {
            if (rs != null) rs.close();
            if (stmt != null) stmt.close();
            if (conn != null) conn.close();
        } catch (SQLException e) {
            e.printStackTrace();
        }
    }
    
    public static void closeConnection(Connection conn, Statement stmt) {
        closeConnection(conn, stmt, null);
    }
}